/**
 @file ctc_xdata.h

 @date 2022-12-29

 @version v1.0

 The file define api struct used in xData.
*/
#ifndef _CTC_XDATA_H
#define _CTC_XDATA_H
#ifdef __cplusplus
extern "C" {
#endif

#include "ctc_const.h"
#include "ctc_common.h"
#include "ctc_field.h"


/****************************************************************
*
*common
*
****************************************************************/

/**
 @brief define chip global configure
*/
struct ctc_xdata_global_cfg_s
{
    uint8 mode;          /**< [AT] 0: sdk researve: 1:support user configure all xdata path (default: 0)*/
};
typedef struct ctc_xdata_global_cfg_s ctc_xdata_global_cfg_t;


struct ctc_xdata_field_s
{
    uint8 width;            /**< [AT] width, refer to ctc_xdata_width_t */
    uint8 offset;           /**< [AT] offset */
    uint8 flag;             /**< [AT] flag, refer to ctc_xdata_field_flag_t */
    uint32 data;            /**< [AT] data */
    uint32 mask;            /**< [AT] mask */
};
typedef struct ctc_xdata_field_s ctc_xdata_field_t;

struct ctc_xdata_s
{
    uint8 prof_id;                   /**< [AT] profile id */
    uint8 type;                      /**< [AT] type, refer to ctc_xdata_prof_type_t or ctc_xdata_local_type_t*/
    uint8 num;                       /**< [AT] valid fields number */
    ctc_xdata_field_t* fields;       /**< [AT] fields, refer to ctc_xdata_field_t */
};
typedef struct ctc_xdata_s ctc_xdata_t;


/****************************************************************
*
*xdata
*
****************************************************************/

enum ctc_xdata_field_flag_e
{
    CTC_XDATA_FIELD_FLAG_UDF      = (1U << 0),
};
typedef enum ctc_xdata_field_flag_e ctc_xdata_field_flag_t;

enum ctc_xdata_width_e
{
    CTC_XDATA_WIDTH_0 = 0,         /**< [AT] invalid xdata width */
    CTC_XDATA_WIDTH_4 = 4,         /**< [AT] support 4 bits width */
    CTC_XDATA_WIDTH_8 = 8,         /**< [AT] support 8 bits width */
    CTC_XDATA_WIDTH_16 = 16,       /**< [AT] support 16 bits width */
    CTC_XDATA_WIDTH_32 = 32,       /**< [AT] support 32 bits width */
};
typedef enum ctc_xdata_width_e ctc_xdata_width_t;

enum ctc_xdata_prof_type_e
{
    CTC_XDATA_PROF_TYPE_POST_SCL,         /**< [AT] xdata for post SCL */
    CTC_XDATA_PROF_TYPE_POST_L3IF,        /**< [AT] xdata for post L3IF */
    CTC_XDATA_PROF_TYPE_POST_TUNNEL,      /**< [AT] xdata for post TUNNEL */
    CTC_XDATA_PROF_TYPE_POST_FWD,         /**< [AT] xdata for post FWD */
    CTC_XDATA_PROF_TYPE_POST_ACL,         /**< [AT] xdata for post ACL */
    CTC_XDATA_PROF_TYPE_POST_MAX,

    CTC_XDATA_PROF_TYPE_DSSCL = CTC_XDATA_PROF_TYPE_POST_MAX, /**< [AT] xdata for DsScl */
    CTC_XDATA_PROF_TYPE_DSTUNNEL,         /**< [AT] xdata for DsTunnel */
    CTC_XDATA_PROF_TYPE_DSMPLS,           /**< [AT] xdata for DsMpls */
    CTC_XDATA_PROF_TYPE_DSMACDA,          /**< [AT] xdata for DsMacDa, prof_id 0, used for DsMacDa; 1, used for DsMacDaDefault */
    CTC_XDATA_PROF_TYPE_DSIPDA,           /**< [AT] xdata for DsIpDa */
    CTC_XDATA_PROF_TYPE_DSFLOW,           /**< [AT] xdata for DsFlow */
    CTC_XDATA_PROF_TYPE_DSACL,            /**< [AT] xdata for DsAcl */
    CTC_XDATA_PROF_TYPE_EGS_DSSCL,        /**< [AT] xdata for egress DsScl */
    CTC_XDATA_PROF_TYPE_EGS_DSACL,        /**< [AT] xdata for egress DsAcl */

    CTC_XDATA_PROF_TYPE_MAX
};
typedef enum ctc_xdata_prof_type_e ctc_xdata_prof_type_t;

struct ctc_xdata_map_s
{
    uint8 width;            /**< [AT] width, refer to ctc_xdata_width_t */
    uint8 src_offset;       /**< [AT] source offset */
    uint8 dst_offset;       /**< [AT] dest offset */
};
typedef struct ctc_xdata_map_s ctc_xdata_map_t;

struct ctc_xdata_prof_s
{
    uint8 prof_id;                   /**< [AT] profile id */
    uint8 type;                      /**< [AT] type, refer to ctc_xdata_prof_type_t */
    uint8 num;                       /**< [AT] valid mapping number */
    ctc_xdata_map_t* map;            /**< [AT] mapping info, refer to ctc_xdata_map_t */
};
typedef struct ctc_xdata_prof_s ctc_xdata_prof_t;

/****************************************************************
*
*local xdata
*
****************************************************************/

enum ctc_xdata_local_type_e
{
    CTC_XDATA_LOCAL_TYPE_SCL,             /**< [AT] local xdata for SCL */
    CTC_XDATA_LOCAL_TYPE_EGS_SCL,         /**< [AT] local xdata for egress SCL */
    CTC_XDATA_LOCAL_TYPE_FLOW_HASH,       /**< [AT] local xdata for FLOW HASH */
    CTC_XDATA_LOCAL_TYPE_FLOW_HASH_EXT,   /**< [AT] local xdata for FLOW HASH EXT */
    CTC_XDATA_LOCAL_TYPE_IPFIX,           /**< [AT] local xdata for IPFIX */
    CTC_XDATA_LOCAL_TYPE_EGS_IPFIX,       /**< [AT] local xdata for egress IPFIX */
    CTC_XDATA_LOCAL_TYPE_MAX
};
typedef enum ctc_xdata_local_type_e ctc_xdata_local_type_t;

typedef struct ctc_xdata_local_kset_s {
    uint32 w[CTC_B2W_SIZE(CTC_FIELD_KEY_NUM)];
} ctc_xdata_local_kset_t;

struct ctc_xdata_local_s
{
    uint8 type;                          /**< [AT] type, refer to ctc_xdata_local_type_t */
    uint8 mode;                          /**< [AT] 0, only use xdata in the path; 
                                                   1, only use local fixed fields; 
                                                   2, use local fixed fields replace xdata in the path*/
    uint8 num;                           /**< [AT] valid fields number */
    ctc_xdata_map_t* fields;             /**< [AT] fields, only valid for mode 2 */
};
typedef struct ctc_xdata_local_s ctc_xdata_local_t;


/****************************************************************
*
*xdata path
*
****************************************************************/
enum ctc_xdata_path_flag_e
{
    CTC_XDATA_PATH_STACKING_EN      = (1U << 0),   /**< [AT] If set, stacking header will with xdata(0~59bits), valid for CTC_XDATA_PATH_TYPE_IPE_BSR*/
};
typedef enum ctc_xdata_path_flag_e ctc_xdata_path_flag_t;

enum ctc_xdata_path_fixed_field_e
{
    CTC_XDATA_FIXED_FIELD_LOGIC_PORT_EXT      = (1U << 0),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR and CTC_XDATA_PATH_TYPE_BSR_EPE */
    CTC_XDATA_FIXED_FIELD_HASH_VALUE          = (1U << 1),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR and CTC_XDATA_PATH_TYPE_BSR_EPE */
    CTC_XDATA_FIXED_FIELD_NAT_L4_SRC_PORT     = (1U << 2),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR and CTC_XDATA_PATH_TYPE_BSR_EPE */
    CTC_XDATA_FIXED_FIELD_ECMP_HASH_HIGH      = (1U << 3),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR, CTC_XDATA_PATH_TYPE_BSR_EPE and CTC_XDATA_PATH_TYPE_IPE_LOCAL_BSR*/
    CTC_XDATA_FIXED_FIELD_NAT_L4_DST_PORT     = (1U << 4),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR and CTC_XDATA_PATH_TYPE_BSR_EPE */
    CTC_XDATA_FIXED_FIELD_APS_PROTECTING_EN   = (1U << 5),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR and CTC_XDATA_PATH_TYPE_BSR_EPE */
    CTC_XDATA_FIXED_FIELD_FWD_TYPE            = (1U << 6),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR and CTC_XDATA_PATH_TYPE_BSR_EPE */
    CTC_XDATA_FIXED_FIELD_L3IF_ID             = (1U << 7),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_LOCAL_BSR */
    CTC_XDATA_FIXED_FIELD_EFD                 = (1U << 8),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_LOCAL_BSR */
    CTC_XDATA_FIXED_FIELD_DNAT_L4_DST_PORT    = (1U << 9),  /**< [AT] valid for CTC_XDATA_PATH_TYPE_IPE_BSR and CTC_XDATA_PATH_TYPE_BSR_EPE */
    CTC_XDATA_FIXED_FIELD_INGRESS_EN          = (1U << 10), /**< [AT] valid for CTC_XDATA_PATH_TYPE_EPE_LOOP1 */
};
typedef enum ctc_xdata_path_fixed_field_e ctc_xdata_path_fixed_field_t;


enum ctc_xdata_path_type_e
{
    CTC_XDATA_PATH_TYPE_IPE_BSR,        /**< [AT] xdata path of IPE to BSR */
    CTC_XDATA_PATH_TYPE_IPE_LOCAL_BSR,  /**< [AT] xdata path of IPE to local BSR */
    CTC_XDATA_PATH_TYPE_BSR_EPE,        /**< [AT] xdata path of BSR to EPE */
    CTC_XDATA_PATH_TYPE_EPE_LOOP0,      /**< [AT] xdata[0:63] path of EPE to loop */
    CTC_XDATA_PATH_TYPE_EPE_LOOP1,      /**< [AT] xdata[64:127] path of IPE to local loop */
    CTC_XDATA_PATH_TYPE_LOOP0_IPE,      /**< [AT] xdata[0:63] path of loop to IPE */
    CTC_XDATA_PATH_TYPE_LOOP1_IPE,      /**< [AT] xdata[64:127] path of local loop to IPE */
    CTC_XDATA_PATH_TYPE_MAX
};
typedef enum ctc_xdata_path_type_e ctc_xdata_path_type_t;

struct ctc_xdata_path_s
{
    uint8 prof_id;                /**< [AT] profile id */
    uint8 type;                   /**< [AT] type, refer to ctc_xdata_path_type_t */
    uint8 flag;                   /**< [AT] flag, refer to ctc_xdata_path_flag_t */
    uint8 num;                    /**< [AT] valid field number */
    ctc_xdata_map_t* map;         /**< [AT] mapping info, refer to ctc_xdata_map_t */
    uint16 fixed_bmp;             /**< [AT] fixed bitmap, refer to ctc_xdata_path_fixed_field_t */
};
typedef struct ctc_xdata_path_s ctc_xdata_path_t; 

#ifdef __cplusplus
}
#endif

#endif
